<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%String path = request.getContextPath(); %>
<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title>欢迎页面-X-admin2.2</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
      
        <link rel="stylesheet" href="<%=path %>/back/css/font.css">
        <link rel="stylesheet" href="<%=path %>/back/css/xadmin.css">
        <script type="text/javascript" src="<%=path %>/back/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="<%=path %>/back/js/xadmin.js"></script>
            <script type="text/javascript" src="<%=path%>/back/js/jquery-3.5.1.min.js"></script>
            
            <link rel="stylesheet" type="text/css" href="https://www.huangwx.cn/css/sweetalert.css">
		<script type="text/javascript" src="https://www.huangwx.cn/js/sweetalert-dev.js"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
        <!--[if lt IE 9]>
            <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
            <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
    <!-- css居中 -->
    <style type="text/css">
    	.center{
    	margin-top:100px;
    	}
    </style>
        <div id="connect" class="center">
            
				                <form id="myform"  method="post"  action="<%=path%>/CookTypeServlet?action=add" class="layui-form">
						                  <div class="layui-form-item">
						                      <label for="username" class="layui-form-label">
						                          <span class="x-red">*</span>菜谱名称
						                      </label>
						                      <div class="layui-input-inline">
						                          <input type="text" id="checkCookName" name="cookTypeName"  class="layui-input">
						                      </div>
						                      <div class="layui-form-mid layui-word-aux">
						                          <span  class="x-red">*</span>
						                          <span id="checkCookTypeName">将加入菜谱列</span>
						                      </div>
						                  </div>					
						                  <div class="layui-form-item">
						                      <label for="L_repass" class="layui-form-label">
						                      </label>
						                      <input id="button" type="button" value="提交"   class="layui-btn" >        
						                  </div>
				              </form>
	      </div>
<!-- --------失去焦点验证是否重名 -->
<script type="text/javascript">
$(function(){
	$("#checkCookName").blur(isReName);
})

function isReName ()
	{
		var cookTypeName = $("#checkCookName").val();
		var flag =false;
		
		$.ajax({
			url:"<%=path%>/CookTypeServlet",
			type:"post",
			async:false,
			data:{action:"isRename",cookTypeName:cookTypeName},
			success:function(mes){
				if(mes=="1")//重名
					{
						$("#checkCookTypeName").html("菜谱名称重复！请重新添加");						
						flag=false;
					}
				if(mes=="0")//不重名
					{
					
						flag=true;
						$("#checkCookTypeName").html("√");
					}
			}
		});//ajax结束
		return flag;	
	}

//ajax增加
$(function(){
	$("#button").click(function(){
		var cookName = $("#checkCookName").val();
		var flag = isReName();
		if(flag==true)//不重名
			{
				$.ajax({
					url:"<%=path%>/CookTypeServlet",
					type:"post",
					async:false,
					data:{action:"add",cookTypeName:cookName},
					success:function(mes){
						swal("增加成功!");
						window.parent.location.href=window.parent.location.href;
						
					}
				});//ajax结束
			}
		else
			{
				swal("菜谱名称请重新增加");
			}
	});//提交按钮结束
})

</script>			              
    
    </body>
</html>
